package cn.stylefeng.guns.modular.transport.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.core.util.DateUtil;
import cn.stylefeng.guns.modular.basic.service.BasicWarehouseService;
import cn.stylefeng.guns.modular.transport.entity.TransportRegistrationSignin;
import cn.stylefeng.guns.modular.transport.model.params.TransportRegistrationSigninParam;
import cn.stylefeng.guns.modular.transport.service.TransportRegistrationSigninService;
import cn.stylefeng.guns.modular.basic.service.BasicOperateService;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.util.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 临时工签到控制器
 *
 * @author 翟登巍
 * @Date 2024-03-05 10:26:53
 */
@Controller
@RequestMapping("/transportRegistrationSignin")
public class TransportRegistrationSigninController extends BaseController {

    private String PREFIX = "/transport/transportRegistrationSignin";

    @Autowired
    private TransportRegistrationSigninService transportRegistrationSigninService;

    @Autowired
    private BasicOperateService basicOperateService;

    @Autowired
    private UserService userService;

    @Autowired
    private BasicWarehouseService basicWarehouseService;
    /**
     * 跳转到主页面
     *
     * @author 翟登巍
     * @Date 2024-03-05
     */
    @RequestMapping("")
    public String index(Model model) {
        User user = userService.getcurrentUser();
        Long deptId = user.getDeptId();
        Long deliverId = user.getDeliverId();
        //查询可选择项目
        model.addAttribute("basicOperatelist", basicOperateService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/transportRegistrationSignin.html";
    }

    /**
     * 新增页面
     *
     * @author 翟登巍
     * @Date 2024-03-05
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/transportRegistrationSignin_add.html";
    }

    /**
     * 编辑页面
     *
     * @author 翟登巍
     * @Date 2024-03-05
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/transportRegistrationSignin_edit.html";
    }

    /**
     * 新增接口
     *
     * @author 翟登巍
     * @Date 2024-03-05
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(TransportRegistrationSigninParam transportRegistrationSigninParam) {
        this.transportRegistrationSigninService.add(transportRegistrationSigninParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author 翟登巍
     * @Date 2024-03-05
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(TransportRegistrationSigninParam transportRegistrationSigninParam) {
        this.transportRegistrationSigninService.update(transportRegistrationSigninParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author 翟登巍
     * @Date 2024-03-05
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(TransportRegistrationSigninParam transportRegistrationSigninParam) {
        this.transportRegistrationSigninService.delete(transportRegistrationSigninParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author 翟登巍
     * @Date 2024-03-05
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(TransportRegistrationSigninParam transportRegistrationSigninParam) {
        TransportRegistrationSignin detail = this.transportRegistrationSigninService.getById(transportRegistrationSigninParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author 翟登巍
     * @Date 2024-03-05
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(TransportRegistrationSigninParam transportRegistrationSigninParam,String condition ,String startTime,String endTime) {
        User user = userService.getcurrentUser();
        if (ToolUtil.isNotEmpty(startTime) && ToolUtil.isNotEmpty(endTime)) {
            transportRegistrationSigninParam.setStartTime("'"+startTime+"' and '"+endTime+"'");
        } else if (startTime == null && endTime == null){
            startTime = DateUtil.getDate();
            endTime = DateUtil.getDate();
            transportRegistrationSigninParam.setStartTime("'"+startTime+"' and '"+endTime+"'");
        }
        transportRegistrationSigninParam.setDeliverId(user.getDeliverId());
        transportRegistrationSigninParam.setDeptId(user.getDeptId());
        if(ToolUtil.isEmpty(transportRegistrationSigninParam.getOperateId())){
            transportRegistrationSigninParam.setOperateId(-1L);
        }

        return this.transportRegistrationSigninService.findPageBySpec(transportRegistrationSigninParam,condition);
    }

}


